
do "E:/ReplicateBuild/02_code/00_environment/00_set_environment.do"

** 2016 data

global sy = 2016


global year_minus_1 = $sy-1

local hh = ""

use "$basedata/ncerdc_teacher_tests", clear
collapse (mean) teacher_test_score_std, by(ncerdc_id)
ren teacher_test_score_std praxis
tempfile temptest
save `temptest', replace

use "$basedata/ncerdc_education", clear
gen grad_degree = (educational_attainment>=5)
collapse (max) grad_degree, by(ncerdc_id)
tempfile tempeducation
save `tempeducation', replace


use "$basedata/ncerdc_teacher_certification", clear
gen certified = (firstyr<=$sy)
keep ncerdc_id certified
tempfile tempcert
save `tempcert', replace

use "$basedata/ncerdc_teacher_license", clear
collapse (min) firstyr=hq_fy, by(ncerdc_id)
gen licensed = (firstyr<=$sy)
keep ncerdc_id licensed
tempfile templic
save `templic', replace

use "$basedata/allLEA_teacher_year_data", clear
bys ncerdc_id ncerdc_lea ncerdc_schlcode: egen lastyr_school = max(sy)
bys ncerdc_id ncerdc_lea: egen lastyr_district = max(sy)

qui summ sy
local maxyear = r(max)

gen attrition_school = (sy==lastyr_school & sy!=. & sy<`maxyear')
gen attrition_district = (sy==lastyr_district & sy!=. & sy<`maxyear')

keep if sy==$sy

collapse (max) attrition_school attrition_district, by(ncerdc_id)

tempfile tempattrition
save `tempattrition', replace

use "$basedata/ncerdc_demographics", clear
keep ncerdc_id dob
sort ncerdc_id
tempfile tempdob
save `tempdob', replace

use "$basedata/va_estimates_drift", clear

keep if t==$sy

keep if s!=.
sort j t schlcode lea

bys j t: egen num_obs = count(s)
tab num_obs
drop if num_obs>1
drop num_obs

ren j ncerdc_id
sort ncerdc_id

merge 1:1 ncerdc_id using `temptest'
drop if _m==2
drop _m

merge 1:1 ncerdc_id using `tempeducation'
drop if _m==2
drop _m

merge 1:1 ncerdc_id using `tempcert'
drop if _m==2
drop _m
replace certified = 0 if certified==.

merge 1:1 ncerdc_id using `templic'
drop if _m==2
drop _m
replace licensed = 0 if licensed==.

merge 1:1 ncerdc_id using `tempattrition'
drop if _m==2
drop _m

merge 1:1 ncerdc_id using `tempdob'
drop if _m==2
drop _m
gen age = ${sy}-year(dob)
replace age = . if age<20 | age>80

* experience: e_ma

gen e0 = (e_ma==0)
gen e1_2 = (e_ma>=1 & e_ma<=2)
gen e3_5 = (e_ma>=3 & e_ma<=5)
gen e6_12 = (e_ma>=6 & e_ma<=12)
gen e13_20 = (e_ma>=13 & e_ma<=20)
gen e21_27 = (e_ma>=21 & e_ma<=27)
gen e28 = (e_ma>=28)

gen FOCAL = lea_ma=="XXX" // hide identity

bys lea_ma schlcode_ma: egen s_n_ct_m1_ma = sum(n_ct_m1_ma)
bys lea_ma schlcode_ma: egen s_n_ct_m2_ma = sum(n_ct_m2_ma)

gen schoolDISAD = s_n_ct_m2_ma / (s_n_ct_m1_ma+s_n_ct_m2_ma)

gen DISADcat1 = 1+(schoolDISAD>.3)+(schoolDISAD>.7)
gen DISADcat2 = 1+(schoolDISAD>.7)

reg mu_jt_hat_preY_ma e0 e1_2 e3_5 e6_12 e13_20 e21_27 e28 grad_degree licensed certified praxis
local r2 = e(r2)
estadd ysumm
eststo reg1

reg mu_jt_m1_hat_preY_ma e0 e1_2 e3_5 e6_12 e13_20 e21_27 e28 grad_degree licensed certified praxis
local r2 = e(r2)
estadd ysumm
eststo reg2

reg mu_jt_m2_hat_preY_ma e0 e1_2 e3_5 e6_12 e13_20 e21_27 e28 grad_degree licensed certified praxis
local r2 = e(r2)
estadd ysumm
eststo reg3



label var mu_jt_hat_preY_ma "VA Mean"
label var mu_jt_m1_hat_preY_ma "VA Adv"
label var mu_jt_m2_hat_preY_ma "VA Disadv"
label var e1_2 "Experience 1-2"
label var e3_5 "Experience 3-5"
label var e6_12 "Experience 6-12"
label var e13_20 "Experience 13-20"
label var e21_27 "Experience 21-27"
label var e28 "Experience 28+"
label var grad_degree "Graduate degree"
label var licensed "Regular license"
label var certified "NBPTS certified"
label var praxis "Praxis"


esttab reg1 reg2 reg3 ///
using "$tables/vam_by_characteristics.tex", replace se label booktabs ///
nostar   ///
substitute(\_ _)  ///
keep (e1_2 e3_5 e6_12 e13_20 e21_27 e28 grad_degree licensed certified praxis) ///
stats(ymean r2 N, labels ("Mean DV" "R squared" "N")) nonote nonumbers 

